How to automatically complete approval tasks in Power Automate and Microsoft Teams
Table of contents:
When writing my previous post on working with Tasks in Power Automate I realized existence of a column name Flow Notification URI inside of Flow Approval table, which I so far really underestimated. Let me show you how powerful it is!
Until today I was nearly sure it is impossible to automatically complete a task in Power Automate/ Microsoft Teams and as well to resume a process that is waiting for approval. It turns out I was really wrong.
Some basicis
Each time a workflow that contains an action which assigns a task and waits for completion is executed, it not only creates entries in Approval and Approval Request tables, but also in Flow Approval. Furthermore, each entry in that last table contains a value in column called Flow Notification URI
, that when called with POST request simply completes waiting and resumes flow:
The URL there is built from the following pieces (most of them is coming from other columns of the Flow Approval table): https://[instance].westeurope.logic.azure.com/workflows/[Flow Id]/runs/[Flow Run Sequence Id]/actions/[Action name that waits for approval]/run?api-version=2016-06-01&sp=%2Fruns%2F[Flow Run Sequence Id]%2Factions%2F[Action name that waits for approval]%2Frun%2C%2Fruns%2F[Flow Run Sequence Id]%2Factions%2F[Action name that waits for approval]%2Fread&sv=1.0&sig=[some signature key]
What’s next?
Knowing that making POST request to that URL completes waiting and resumes flow, opens a totally new range of scenarios that can be build around basic approvals, for example using custom Power Apps. Just imagine some of them:
- Approving on behalf
- Waiting for majority of responses
- Allowing requester to finish approval at any time
- and more!
The goal is, that first you need to write and update data in all other tables that Approvals are using (mentioned in my post here), get all the information needed to be sent as a response and after that make a POST to the Notification URI.
Also, when doing such a POST, be sure it is following the expected JSON format and that you put “Content-Type: application/json
” as header:
{
"responses":[
{
"responder":{
"id":"GUID from Users Table",
"displayName":"Responder name",
"email":"Responder mail",
"tenantId":"Tenant ID",
"userPrincipalName":"Responder principal name"
},
"requestDate":"Timestamp",
"responseDate":"Timestamp",
"approverResponse":"Outcome",
"comments":"Comments"
}
],
"responseSummary":"Combined response comments and approvers together with dates",
"completionDate":"Timestamp",
"outcome":"General outcome",
"name":"Approval ID from Approval table",
"title":"Approval name",
"details":"Approval description",
"requestDate":"Timestamp",
"expirationDate":"Timestamp"
}
Once you send such a POST, action will complete waiting and will display all the data as dynamic outcomes, as if it was completed through the task UI:
I hope this post makes you as excited as it made me when I discovered this simple information. Let me know in comments what scenarios you are able now to accomplish!
Lewis Harris-Manley
Hi Tomasz – thanks for the article, looks great! We tried the standard “Request sign-off” approval flow from SharePoint but because it doesn’t wait until all those listed as approvers has approved and instead as soon as one of them approves it marks the document as such, it doesn’t work.
Any ideas of how we can utilise this Flow URI to make the status update in SharePoint wait until all those marked as approvers have actually approved?
Tomasz Poszytek
Hi, indeed the oob sing-off waits for first only. For such purpose you’d need to develop your own approval workflow, where a trigger is “for a selected item”, so that it appears under context menu of a specific item (or you can use list formatting to add a button?). Back to the topic – in that custom approval workflow you can define whichever conditions you need to complete approval – either first or all. You can then extend the basic functionalities with custom flow that is triggered whenever a new record in Approval Responses is added that eg. checks if majority of approvers have already responded and then completes approval π
Mohd Sharif
Hi Tomasz,
I am working on a functionality where I need to complete the approval task on a PowerApp button click. Till now I redirect the user to PowerAutomate action screen for completing the task. Can you help me with scenario.
Tomasz Poszytek
Hey, you can achieve it following steps described in this blog post and the other one: https://poszytek.eu/en/microsoft-en/office-365-en/powerautomate-en/working-with-approval-tasks-in-dataverse/.
Denny OY
Hi Tomasz ,
Iβm working on a approval flow where I need to update the approval action outside the approval flow (using Powerapps ). After watching your videos on YouTube, I can honestly say that you created a work of art.
Iβm new to this field, so could you be able to share me a full account of each step made in that flow.
Tomasz Poszytek
Thank you π
Denis H
Hi Tomasz, can we add a record to Approval Response table, and how?
Tomasz Poszytek
Sure you can. Simply create a new record using Dataverse action in a cloud flow. Just be sure account you use for the connection has sufficient role to write to Approval Response table.
Lianne Harley
Thank you for this. I have tried this but I’m not seeing the benefits. I may have misinterpreted the objective of this method. I would like to automatically approve/reject the approval task by simulating the assignee approving or rejecting, but without them needing to do so. However, this method
– does not record the outcome in the Results field in the Approvals table (the field remains blank).
– does not create a record in the Approval Response table.
– does not close the approval request, it is still in the assignee’s received approval list and the approve/reject buttons are still available for them to action.
All this does is terminate the Start and Wait for an Approval action in the flow. So it does not actually complete and close the approval request, it only terminates the waiting. Is this the point?
We can add 2 more actions to the flow to record the outcome in the Results field in the Approvals table and create a record in the Approval Response table, but is there something we can do to close the approval request to properly simulate an automatic approve/reject decision?
Tomasz Poszytek
Hi, the method described here is just a part of all the steps that are being done when using approvals oob. Regarding your points:
1. Nope, it does not. You must create it yourself by updating related record in Approvals table.
2. Nope, it does not, you need to create response in Approval Response per each task that is completed.
3. Yes, it does not, because it does not update the Approval record’s status to “inactive” – you must do it on your own.
Basically the method described here only allows you to resume the cloud flow that waits for the approval to be completed. All other steps must be done on your own. For details please look for other posts on my blog or navigate to the playlist where I am focusing on many scenarios around approvals: https://www.youtube.com/watch?v=45f8mRAiNjo&list=PLaHN-sDizNyWt1_qajlDZsFOU-A68ZVe0&ab_channel=TomaszPoszytek.
I am not aware of any endpoint or any other way apart from oob to really trigger approval to be completed (and data to all related tables written automatically).
Elliot J
Hi Tomasz. Really great content, thank you for doing all of the hard work to put this together. Question for you – your example here shows how to complete a ‘Start and Wait for an Approval’ action. Will this work on the standalone ‘Wait for an Approval’ action? I’ve tried to get this to work per your examples (in the other Dataverse article you mention as well) and my ‘Wait for an Approval’ action just won’t complete. Any ideas?
Tomasz Poszytek
Thanks! Regarding your question – when you use one action to start approval and other to wait, there are two records in Flow Approval table – one per each action. However only the first action has the Approval ID equal the one form Approval table. The other one has Sequence ID equal to the one in the first record π It’s quite unclear, but to get the proper Flow Notification URI you need to find the second record π Possibly you’ll find explanation in this video: https://www.youtube.com/watch?v=bqOftVN7J_Y&list=PLaHN-sDizNyWt1_qajlDZsFOU-A68ZVe0&index=4&ab_channel=TomaszPoszytek.
Elliot J
To clarify, I get the error ‘The request failed. Error code: ‘ApprovalSubscriptionNotAllowed’. Error Message: ‘Cannot wait on this approval in its current state.’.’ when the Wait for an Approval action completes. I’ve made sure that the approval records are not set to ‘completed’ before the trigger executes.
OmarSaleh
Thanks so much Thamasz for this great article. I understood the concept, but not really sure how to do the POST action to resume the flow. Have you made a youtube video for this? Thanks!
Tomasz Poszytek
Hey, sure! Many of them: https://www.youtube.com/playlist?list=PLaHN-sDizNyWt1_qajlDZsFOU-A68ZVe0